<template>
  <el-dialog v-model="dialogShow7" width="30%">
          <div class="titleShow">
            <div class="titles">{{ $t('licence.sys_powerFactor') }}</div>
          </div>
          <el-radio style="display: block; margin-bottom: 20px" v-model="switchS" label="1">{{
            $t('licence.sys_kaiqi') }}</el-radio>
          <el-radio style="display: block; margin-bottom: 20px" v-model="switchS" label="2">{{
            $t('licence.sys_guanbi') }}</el-radio>
          <el-form :inline="true" :model="formInline" :rules="rules" ref="formInlines" class="demo-form-inline"
            v-show="switchS == 1">
            <el-form-item :label="$t('licence.sys_gonglv')" prop="num_5">
              <el-input v-model="formInline.num_5" :placeholder="$t('licence.sys_gonglvshuzhi')"
                style="width: 350px"></el-input>
            </el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="dialogShow7 = false">{{ $t('licence.cancel') }}</el-button>
              <el-button type="primary" @click="instruction">{{ $t('licence.determine') }}</el-button>
            </span>
          </template>
        </el-dialog>
</template>
<script setup lang="ts">
import { commandControl } from "@/api/inveter/inveter";
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const dialogShow7 = ref(false) //功率因数调节
const props = defineProps(['ids','lang','powerStation']);
const formInlines = ref<ElFormInstance>();
const switchS = ref<number | string>(1) //功率因数调节控制
const formInline = ref({
  num_5: '' as any,
})
const rules = reactive({
  num_5: [
    {
      required: true,
      message: t("licence.sys_shurushuzhi"),
      trigger: "blur",
    },
  ],
});
const instruction = async ()=>{
  if (switchS.value == 1) {
      await formInlines.value?.validate();
      if (
        (formInline.value.num_5 >= -1000 && formInline.value.num_5 <= -900) ||
        (formInline.value.num_5 >= 900 && formInline.value.num_5 <= 1000)
      ) {
        ElMessageBox.confirm(t("licence.Submit"), t("licence.Tips"), {
          confirmButtonText: t("licence.determine"),
          cancelButtonText: t("licence.cancel"),
          type: "warning",
        })
          .then(async () => {
            let data = {
              commandId: 7,
              ids: props.ids.join(","),
              setVal: formInline.value.num_5,
              type: switchS.value,
              lang: props.lang,
            };
            await commandControl(data);
            ElMessage({
              type: "success",
              message: t("licence.success"),
            });
          })
          .catch(() => {
            ElMessage({
              type: "info",
              message: t("licence.cancels"),
            });
          });
        dialogShow7.value = false;
      } else {
        ElMessage({
          type: "error",
          message: t("licence.sys_gonglv9"),
        });
      }
    } else {
      ElMessageBox.confirm(t("licence.Submit"), t("licence.Tips"), {
        confirmButtonText: t("licence.determine"),
        cancelButtonText: t("licence.cancel"),
        type: "warning",
      })
        .then(async () => {
          let data = {
            commandId: 7,
            ids: props.ids.join(","),
            // setVal: formInline.value.num_5,
            type: switchS.value,
            lang: props.lang,
          };
          await commandControl(data);
          ElMessage({
            type: "success",
            message: t("licence.success"),
          });
        })
        .catch(() => {
          ElMessage({
            type: "info",
            message: t("licence.cancels"),
          });
        });
      dialogShow7.value = false;
    }
}
const openDialog = () => {
  dialogShow7.value = true;
  formInline.value.num_5 = "";
  switchS.value = "1"; //功率因数调节控制  
}
defineExpose({
  openDialog
})
</script>